package com.music.glide.util.pool

import kotlin.concurrent.Volatile

abstract class KStateVerifier private constructor() {

    abstract fun throwInRecycled()

    abstract fun setRecycled(isRecycled: Boolean);

    companion object {
        fun newInstance():KStateVerifier {
            return DefaultStateVerifier()
        }
    }

    class DefaultStateVerifier : KStateVerifier(){

        @Volatile
        private var  isReleased = false

        override fun throwInRecycled() {
            if (isReleased){
                throw IllegalStateException("Already release")
            }
        }

        override fun setRecycled(isRecycled: Boolean) {
            this.isReleased = isRecycled
        }
    }
}